package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.provider.exceptions.OmcBizException;
import com.csun.cmny.provider.model.dto.OldmanRpcDto;
import com.csun.cmny.provider.model.vo.OldmanBedRoomBuildingVo;
import com.csun.cmny.provider.model.vo.OldmanRpcVo;
import com.csun.cmny.provider.model.vo.RoomBuildingVo;
import com.csun.cmny.provider.model.vo.nursing.NursingGroupOldmanVo;
import com.csun.cmny.provider.model.vo.nursing.NursingGroupRoomVo;
import com.csun.cmny.provider.model.vo.nursing.NursingGroupUserVo;
import com.csun.cmny.provider.service.OmcOldmanFeignApi;
import com.csun.cmny.provider.service.OmcRoomFeignApi;
import com.csun.cmny.provider.service.OmcRpcService;
import com.csun.cmny.util.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-01-22 14:25
 * @Description: the class omc rpc service impl
 */
@Slf4j
@Service
public class OmcRpcServiceImpl implements OmcRpcService {

    @Resource
    private OmcOldmanFeignApi omcOldmanFeignApi;

    /**
     * query nursing group user by user id
     *
     * @param userId the user id
     * @return the nursing group user vo
     */
    @Override
    public NursingGroupUserVo queryNursingGroupUserByUserId(Long userId) {

        try {
            Wrapper<NursingGroupUserVo> wrapper = omcOldmanFeignApi.queryNursingGroupUserByUserId(userId);
            if (wrapper == null) {
                throw new OmcBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new OmcBizException(ErrorCodeEnum.DMC100610061);
            }

            NursingGroupUserVo result = wrapper.getResult();

            assert result != null;

            return result;
        } catch (Exception e) {
            log.error("queryNursingGroupUserByUserId={}", e.getMessage(), e);
        }

        return null;
    }

}
